package com.itheima.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo4 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
        Class aClass = Class.forName("com.itheima.reflect.Student");
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
        System.out.println("----------------------");
        Method[] methods1 = aClass.getDeclaredMethods();
        for (Method method : methods1) {
            System.out.println(method);
        }
        System.out.println("----------------------");
        Method getAge = aClass.getMethod("getAge");
        System.out.println(getAge);
        Method study = aClass.getDeclaredMethod("Study", String.class);
        study.setAccessible(true);
        System.out.println(study);
        Student stu = (Student) aClass.newInstance();
        Object zhangsan = study.invoke(stu, "zhangsan");
        System.out.println(zhangsan);
    }
}
